home *** CD-ROM | disk | FTP | other *** search
/ Compendium Deluxe 1 / LSD Compendium Deluxe 1.iso / a / programming / assembly / consume.lha / shikina.s < prev    next >
Encoding:
Text File  |  1993-04-24  |  7.6 KB  |  246 lines

  1. *******************************************************************************
  2.  
  3.         incdir    'df0:include/'
  4.         include    'intuition/intuition.i'
  5.         include    'intuition/intuition_lib.i'
  6.         include    'exec/io.i'
  7.         include    'exec/exec_lib.i'
  8.         include    'devices/input.i'
  9.         include    'devices/inputevent.i'
  10.         include    'libraries/dosextens.i'
  11.         include    'libraries/dos_lib.i'
  12.  
  13. NULL        equ    0
  14.  
  15. CALLSYS        MACRO
  16.         movea.l    (4).w,a6
  17.         jsr    _LVO\1(a6)
  18.         ENDM
  19.  
  20. *******************************************************************************
  21. *                                                                             *
  22. * This first hunk, handily based on the ProTracker Source, will run the next  *
  23. * code hunk in the background and release the CLI for other uses.             *
  24. *                                                                             *
  25. *******************************************************************************
  26.  
  27.         section    RunBackHunk,CODE
  28.  
  29. rb_HunkStart:    sub.l    a1,a1            ; a1 = 0 = find our task
  30.         CALLSYS    FindTask        ; Find our task/process
  31.         move.l    d0,a4            ; process in a4
  32.         moveq.l    #0,d0            ; no WB msg ptr
  33.         tst.l    pr_CLI(a4)        ; are we called from CLI?
  34.         bne.s    CalledFromCLI        ; yes, do other stuff
  35.         lea    pr_MsgPort(a4),a0    ; running from wb, otherwise
  36.         CALLSYS    WaitPort        ; wait for the WB msg
  37.         lea    pr_MsgPort(a4),a0    ;
  38.         CALLSYS    GetMsg            ; get the WB msg
  39.         
  40. CalledFromCLI:    move.l    d0,d7            ; d7 = WB msg
  41.         lea    DOSLib,a1        ; 'dos.library'
  42.         moveq.l    #0,d0            ; and ol' version
  43.         CALLSYS    OpenLibrary        ; open it
  44.         tst.l    d0            ; did we get it?
  45.         beq.s    QuickExit        ; I sure hope so!!
  46.         move.l    d0,_DOSBase        ; save dosbase ptr
  47.  
  48.         CALLSYS    Forbid            ; stop multitasking for a sec
  49.         move.l    #ProgName,d1        ; ptr to the name of the prog
  50.         moveq.l    #0,d2            ; zero out d2
  51.         move.b    LN_PRI(a4),d2        ; priority
  52.         lea    rb_HunkStart-4(pc),a0    ; get ptr to next hunk
  53.         move.l    (a0),d3            ; ptr to next segment
  54.         clr.l    (a0)            ; unlink segment
  55.         move.l    #4000,d4        ; stack size
  56.         CALLDOS    CreateProc        ; spawn the process
  57.         CALLSYS    Permit            ; multitasking on
  58.  
  59. QuickExit:    tst.l    d7            ; is there a WB msg?
  60.         beq.b    RBExit            ; no, skip this part
  61.         CALLSYS    Forbid            ; yes, multitask off
  62.         move.l    d7,a1            ; move msg ptr to a1
  63.         CALLSYS    ReplyMsg        ; reply to the message
  64. RBExit:        moveq.l    #0,d0            ; result code = 0
  65.         rts                ; program returns to DOS here
  66.         
  67. *******************************************************************************
  68.  
  69.         section    Main,CODE
  70.         
  71. MainStart:    bra.w    OpenAll            ; open everything we need
  72.  
  73. main:        move.l    UserPort,a0        ; adr of window's msg port
  74.         CALLSYS    WaitPort        ; wait for a message
  75.         move.l    d0,a1            ; message ptr in d0->a1
  76.  
  77.         move.l    UserPort,a0        ; adr of msg port
  78.         CALLSYS    GetMsg            ; retrieve the message
  79.         move.l    d0,a1            ; message ptr in d0, a1
  80.         move.l    im_Class(a1),d2        ; message class in d2
  81.         move.w    im_Code(a1),d3        ; message code in d3
  82.         CALLSYS    ReplyMsg        ; send the message back
  83.         
  84.         cmp.l    #CLOSEWINDOW,d2        ; was it a CLOSEWINDOW msg?
  85.         bne.b    NotCloseWindow        ; no
  86.         st.b    Exit            ; yes
  87. NotCloseWindow:
  88.         tst.b    Exit            ; are we done?
  89.         beq.b    main            ; no, so repeat
  90.  
  91.         bra.w    CloseAll        ; clean up everything
  92.         
  93. *******************************************************************************
  94.  
  95. InputHandler:    movem.l    d1-d7/a0-a6,-(sp)
  96.  
  97.         move.l    a0,a1            ; save ptr to first event
  98. ih_Start:    cmp.b    #IECLASS_RAWKEY,ie_Class(a0)
  99.         bne.b    NotAKey            ; it was not a rawkey event
  100.         move.w    ie_Code(a0),d1        ; get the keycode
  101.         cmp.b    #$20,d1            ; an l?
  102.         bne.b    NotL            ; nope
  103.         move.w    #$12,ie_Code(a0)    ; yes, make it an r
  104.         bra.b    Next            ; look for next event
  105.         
  106. NotL:        cmp.b    #$12,d1            ; got an r?
  107.         bne.b    Next            ; no
  108.         move.w    #$20,ie_Code(a0)    ; yes, make it an l
  109.         bra.b    Next            ; look for next event
  110.  
  111. NotAKey:    cmp.b    #IECLASS_RAWMOUSE,ie_Class(a0)
  112.         bne.b    Next            ; not a mouse event
  113.         neg.w    ie_X(a0)        ; reverse mouse x movements
  114.         neg.w    ie_Y(a0)        ; reverse mouse y movements
  115.  
  116. Next:        move.l    (a0),a0            ; get ptr to next event
  117.         cmp.l    #NULL,a0        ; is there a next event?
  118.         bne.b    ih_Start        ; yes, loop again
  119.         move.l    a1,d0            ; pass ptr to first event
  120.         movem.l    (sp)+,d1-d7/a0-a6    ;   in list to next handler
  121.         rts                ; end of interrupt
  122.  
  123. *******************************************************************************
  124.  
  125. OpenAll:    lea    IntuitionLib,a1        ; 'intuition.library'
  126.         moveq.l    #33,d0            ; version 33 or higher
  127.         CALLSYS    OpenLibrary        ; try to open it
  128.         tst.l    d0            ; did we get it?
  129.         beq.w    Error            ; no
  130.         move.l    d0,_IntuitionBase    ; yes, keep the ptr
  131.  
  132.         lea    MyNewWindow,a0        ; adr of newwindow struct
  133.         CALLINT    OpenWindow        ; try to open it
  134.         tst.l    d0            ; did we get it?
  135.         beq.w    Error            ; no
  136.         move.l    d0,MyWindow        ; yes, keep the ptr
  137.         move.l    d0,a0            ; window ptr in a0
  138.         move.l    wd_UserPort(a0),UserPort
  139.                         ; get address of window msgport
  140.         sub.l    a1,a1            ; a1 = 0 = find our task
  141.         CALLSYS    FindTask        ; do it
  142.         lea    InputPort,a1        ; reply port for input device
  143.         move.l    d0,MP_SIGTASK(a1)    ; signal us when msg received
  144.         CALLSYS    AddPort            ; add the port to the system
  145.         
  146.         lea    InputDevName,a0        ; 'input.device'
  147.         lea    InputIOReq,a1        ; IOStdReq structure for it
  148.         move.l    #InputPort,MN_REPLYPORT(a1)
  149.         moveq.l    #0,d0            ; unit number (n/a)
  150.         moveq.l    #0,d1            ; flags (n/a)
  151.         CALLSYS    OpenDevice        ; try to open input.device
  152.         tst.l    d0            ; got it?
  153.         beq.b    NoError            ; yes, all is well
  154.         moveq.l    #1,d0            ; d0 = 1 = device error
  155.         bra.w    Error            ; shut down
  156. NoError:
  157.         lea    InputIOReq,a1        ; input.device io request
  158.         move.w    #IND_ADDHANDLER,IO_COMMAND(a1)
  159.         move.l    #InputInterrupt,IO_DATA(a1)
  160.         CALLSYS    DoIO            ; install my input handler
  161.                 
  162.         bra.w    main            ; resume with main program
  163.  
  164. *******************************************************************************
  165.  
  166. CloseAll:    cmp.l    #1,d0            ; an opendevice error?
  167.         beq.b    DeviceError        ; yep
  168.  
  169.         lea    InputIOReq,a1        
  170.         move.w    #IND_REMHANDLER,IO_COMMAND(a1)
  171.         move.l    #InputInterrupt,IO_DATA(a1)
  172.         CALLSYS    DoIO            ; remove my input handler
  173.         lea    InputIOReq,a1        
  174.         CALLSYS    CloseDevice        ; close the input.device
  175.  
  176. DeviceError:    lea    InputPort,a1        ; ptr to the msgport
  177.         CALLSYS    RemPort            ; uninstall it
  178.  
  179.         tst.l    MyWindow        ; is the window open?
  180.         beq.b    ca_2            ; no, try the screen
  181.         move.l    MyWindow,a0        ; yes, get the ptr
  182.         CALLINT    CloseWindow        ; and close it
  183.  
  184. ca_2:        tst.l    _IntuitionBase        ; is the intui library open?
  185.         beq.b    ca_1            ; no, exit the program
  186.         move.l    _IntuitionBase,a1    ; yes, get the ptr
  187.         CALLSYS    CloseLibrary        ; and close it
  188.  
  189. ca_1:        CALLSYS    Forbid
  190.         lea    MainStart-4(pc),a0    ; ptr to start of process code
  191.         move.l    a0,d1            ; move to d1
  192.         lsr.l    #2,d1            ; BCPL! Acckk!
  193.         CALLDOS    UnLoadSeg        ; free memory used by process
  194.         move.l    _DOSBase,a1
  195.         CALLSYS    CloseLibrary        ; close dos.library
  196.         CALLSYS    Permit
  197.         rts                ; exit the program
  198.  
  199. *******************************************************************************
  200.  
  201. Error:        moveq.l    #-1,d0            ; repeat 65000+ times
  202. e_Loop:        move.w    #$f00,$dff180        ; flash screen red
  203.         dbra    d0,e_Loop        ; repeat
  204.         bra.w    CloseAll        ; shut ourself down
  205.  
  206. *******************************************************************************
  207.  
  208.         section    TheData,DATA
  209.  
  210. ProgName:    dc.b    'Shikina!',0
  211. IntuitionLib:    dc.b    'intuition.library',0
  212. DOSLib:        dc.b    'dos.library',0
  213. InputDevName:    dc.b    'input.device',0
  214.         even
  215.  
  216. MyNewWindow:    dc.w    0,22,242,11
  217.         dc.b    2,1
  218.         dc.l    CLOSEWINDOW,WINDOWDRAG+WINDOWCLOSE+WINDOWDEPTH
  219.         dc.l    NULL,NULL,WindowTitle,NULL,NULL
  220.         dc.w    16,9,640,200,WBENCHSCREEN
  221. WindowTitle:    dc.b    'Shikina v1.0',0
  222.         even        
  223.  
  224. InputInterrupt:    dc.l    NULL,NULL
  225.         dc.b    NT_INTERRUPT,52
  226.         dc.l    InputInterruptName,NULL,InputHandler
  227. InputInterruptName:
  228.         dc.b    'Shikinterrupt',0
  229.         even
  230.  
  231. *******************************************************************************
  232.  
  233.         section    TheBSS,BSS
  234.  
  235. _IntuitionBase:    ds.l    1
  236. _DOSBase:    ds.l    1
  237. MyWindow:    ds.l    1
  238. UserPort:    ds.l    1
  239. InputIOReq:    ds.b    IOSTD_SIZE
  240. InputPort:    ds.b    MP_SIZE
  241. Exit:        ds.b    1
  242.         even
  243.  
  244. *******************************************************************************
  245.  
  246.